// 主页
<template>
  <div class="installdata">
    <div class="homeData-left">
      <ul>
        <li :class="{'barLi':true,'barSelectLi':isBarSelectLi == index,'barNoSelectLi':isBarNoSelectLi == index}" v-for="(item,index) in barLists" :key="index" @click="barListsClick(index)" @mouseover="barListsMouse(index)">
          {{item.name}}
        </li>
      </ul>
    </div>
    <div class="homeData-right">
      <router-view keep-alive></router-view>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
export default {
  data() {
    return {
      isBarSelectLi: 0, // 选中侧栏
      isBarNoSelectLi: -1, // 未选中侧栏
      barLists: [
        // { name: "企业设置", path: "enterprise" },
        // { name: "通讯录信息", path: "communication" },
        // { name: "更换主管理员", path: "mainmanag" },
        // { name: "设置子管理员", path: "sonmanag" },
        // { name: "版本信息管理", path: "versions" },
        // { name: "修改登录密码", path: "updatepwd" }
      ], //侧栏列表
      barListCopys: [
        { name: "企业设置", path: "enterprise" },
        { name: "通讯录信息", path: "communication" },
        { name: "更换主管理员", path: "mainmanag" },
        { name: "设置子管理员", path: "sonmanag" },
        { name: "版本信息管理", path: "versions" },
        { name: "修改登录密码", path: "updatepwd" }
      ]
    };
  },
  filters: {},
  created: function() {
    var self = this;
    var accessToken = sessionStorage.getItem("accessToken");
    if (accessToken) {
      self.barLists = [];
      if (sessionStorage.getItem("adminType")) {
        if (sessionStorage.getItem("adminType") == "SUB") {
          self.barLists = [
            { name: "企业设置", path: "enterprise" },
            { name: "通讯录信息", path: "communication" },
            { name: "修改登录密码", path: "updatepwd" },
            { name: "版本信息管理", path: "versions" }
          ];
        } else {
          self.barLists = [
            { name: "企业设置", path: "enterprise" },
            { name: "通讯录信息", path: "communication" },
            { name: "更换主管理员", path: "mainmanag" },
            { name: "设置子管理员", path: "sonmanag" },
            { name: "修改登录密码", path: "updatepwd" },
            { name: "版本信息管理", path: "versions" }
          ];
        }
      }
      this.fetchPathFun();
    } else {
      // var warningStr = "没有登录不允许访问,点击确定跳转登录页面";
      // this.$alert(warningStr, "提示", {
      //   confirmButtonText: "确定",
      //   type: "info"
      // })
      //   .then(() => {
          this.$router.push({
            path: "/login"
          });
        // })
        // .catch(() => {
        //   this.$router.push({
        //     path: "/login"
        //   });
        // });
    }
  },
  watch: {},
  methods: {
    // 路由跳转
    fetchPathFun(val) {
      var self = this;
      var valPath = this.$route.path;
      self.barLists.forEach(function(ele, ind) {
        if (
          valPath.indexOf("addSonmanag") > -1 ||
          valPath.indexOf("opSonmanag") > -1 ||
          valPath.indexOf("sonmanag") > -1
        ) {
          if (ele.path.indexOf("sonmanag") > -1) {
            self.isBarSelectLi = ind;
          }
        } else {
          if (valPath.indexOf(ele.path) > -1) {
            self.isBarSelectLi = ind;
          }
        }
      });
    },
    // 点击侧栏
    barListsClick(index) {
      this.isBarSelectLi = index;
      this.isBarNoSelectLi = index;
      this.$router.push({
        path: "/home/install/" + this.barLists[index].path
      });
    },
    // 触摸侧栏
    barListsMouse(index) {
      if (this.isBarSelectLi == index) {
        this.isBarNoSelectLi = -1;
      } else {
        this.isBarNoSelectLi = index;
      }
    },
    ...mapActions([])
  }
};
</script>
<style scoped>
.homeData-left ul {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 15px;
}
.barNoSelectLi {
  background-color: #eeeeee;
}
.barSelectLi {
  background-color: #38adff;
  color: #fff;
}
.barLi {
  width: 100%;
  height: 40px;
  overflow: hidden;
  padding-left: 14px;
  font-size: 14px;
  line-height: 40px;
  cursor: pointer;
  user-select: none;
}
.homeData-left {
  width: 300px;
  background-color: #f4f6f8;
  box-sizing: content-box;
}

.homeData-right {
  width: 898px;
  min-height: 700px;
  background-color: #fff;
  border-left: 1px solid #dedede;
}

.installdata {
  overflow: hidden;
  width: 100%;
  background-color: #fff;
  min-height: 700px;
  display: flex;
  justify-content: space-between;
  border-radius: 5px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}
</style>